﻿using System;
using System.Collections.Generic;
using System.Text;
using OABackground.Entities;
using System.Linq;

namespace OABackground.Infrastructure
{
    public class TeacherInformationRepository
    {
        #region 教师信息增删改查
        public void Add(Teacherinfomation Teacher)//添加一个教师信息
        {

            using (var dbContext = new oaContext())
            {

                dbContext.Add(Teacher);//这不是真的添加
                dbContext.SaveChanges();//用“保存”表示一次事务的完成
            }
        }
        public void Update(Teacherinfomation Teacher)//更新教师信息
        {
            using (var dbContext = new oaContext())
            {
                dbContext.Update(Teacher);
                dbContext.SaveChanges();
            }
        }
        public Teacherinfomation QueryTeacherById(string id)//查找教师信息
        {

            using (var dbContext = new oaContext())
            {
                var teacher = dbContext.Teacherinfomation.FirstOrDefault(x => x.Teacherid == id);
                dbContext.SaveChanges();

                return teacher;
            }
        }
        public void Delete(string Teacherid)//删除教师信息
        {
            using (var dbContext = new oaContext())
            {
                var select = dbContext.Teacherinfomation.Find(Teacherid);
                dbContext.Remove(select);
                dbContext.SaveChanges();
            }

        }
        #endregion
    }
}
